package com.icepeach.icepeachhomeback.service.impl;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.icepeach.icepeachhomeback.entity.User;
import com.icepeach.icepeachhomeback.mapper.UserMapper;
import com.icepeach.icepeachhomeback.req.UserListQueryReq;
import com.icepeach.icepeachhomeback.service.UserService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 张皓冰
* @description 针对表【user(用户表)】的数据库操作Service实现
* @createDate 2023-04-12 10:34:56
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public IPage<User> getUsersByPage(UserListQueryReq userListQueryReq) {
        IPage<User> page=new Page<>(userListQueryReq.getPageNum(),userListQueryReq.getPageSize());
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();
        if(StrUtil.isNotBlank(userListQueryReq.getUsername())){
            queryWrapper.like("username",userListQueryReq.getUsername());
        }
        if(StrUtil.isNotBlank(userListQueryReq.getNickname())){
            queryWrapper.like("username",userListQueryReq.getNickname());
        }
        if(StrUtil.isNotBlank(userListQueryReq.getEmail())){
            queryWrapper.like("username",userListQueryReq.getEmail());
        }
        return baseMapper.selectPage(page,queryWrapper);
    }



}




